<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p>编辑文档</p>
      </div>
      <div class="right-box">
   <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="table-box">
        <div class="item-box">
          <div class="number-box">文档名称</div>
          <div class="number1-box">
            <input type="text" v-model="name" placeholder="请输入文档名称">
          </div>
        </div>
          <div class="item-box">
          <div class="number-box">文档类型</div>
          <div class="number1-box">
            <input type="text" v-model="typea" placeholder="请输入文档类型">
          </div>
        </div>
            <div class="item-box">
          <div class="number-box">文档状态</div>
          <div class="number1-box">
<el-switch
  style="display: block"
  v-model="value2"
  active-color="#13ce66"
  inactive-color="#ff4949"
  active-text="文件下架"
  inactive-text="文件上架">
</el-switch>
          </div>
        </div>
           <div class="item-box">
          <div class="number2-box">文档上传</div>
          <div class="number3-box">
    <el-upload
  class="upload-demo"
  action="/apis/PublicAPI.asmx/UpLoad"
  :on-change="handleChange"
   :on-preview="handlePreview"
  :on-success="afterSuccess"
  :file-list="fileList">
  <el-button size="small" type="primary">点击上传</el-button>
   </el-upload>
          </div>
        </div>
      </div>
         <div class="btn-box">
                <el-button type="primary" @click="addlist()">确定</el-button>
          <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
export default {
    data() {
    return {
      fileList:[],
   equipmentno:"",
   value2:"true",
    typea :"",
   name :"",
   date:"",
   empno:"",
   newlist:{
     UpFileReturn:{
       url:""
     }
   },
   Id:"",
    }
  },
      created() {
    this.empno =JSON.parse(localStorage.getItem('empno'))
    this.Id=this.$route.query.val;
    this. getlist()
  },
  methods:{
    Return(){
      window.history.go(-1);
    },
       afterSuccess(response,file,fileList) {
      var datas = this.$x2js.xml2js(response);
        this.newlist=datas
        console.log(this.newlist)
                },
      handleChange(file, fileList) {
        this.fileList = fileList.slice(-3);
      },
          handlePreview(file) {
        console.log(file);
      },
          getlist() {
      var obj = 
       {
        Id :this.Id,
        }
      ;
      var objs = JSON.stringify(obj);
      axios(
        "/apis//AdministrativeManagement.asmx/Uploaddocument?index=2&jsondata=" + objs+"&empno="+this.empno
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
         var stafflist = JSON.parse(datas.string.__text);
         this.name=stafflist.name
         this.typea=stafflist.typea
        this.newlist.UpFileReturn.url=stafflist.path
              console.log(this.newlist.UpFileReturn.url)
      });
    },
   addlist() {
     console.log(this.value2)
  var obj = 
  {
    Id :this.Id,
   name:this.name,
   typea:this.typea,
   istrue:this.value2,
   path:this.newlist.UpFileReturn.url
  }
      ;
      var objs = JSON.stringify(obj);
      console.log(objs)
      axios(
        "/apis/AdministrativeManagement.asmx/Uploaddocument?index=4&jsondata=" + objs+"&empno="+this.empno
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
      if (datas.string.__text == "ok") {
            this.$message.success("编辑文档成功");
            window.history.go(-1);
          } else {
            this.$message.error(datas.string.__text);
          }
      });
    },
  }
}
</script>
<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.top-box{
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.left-box{
width:100px;
height: 40px;
  float: left;;
margin-top: 10px;
overflow: hidden;
margin-left: 1%;
// border: 1px solid red;
}
.color-box{
  width:5px;
  height: 20px;
  float: left; 
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p{
 float: left; 
 margin-left: 5px;
 line-height: 40px;
}
.right-box{
  float:right;
  width:90px;
 height: 40px;
 margin-right: 2%;
 border-radius: 8px;
 margin-top: 10px;
 background-color:$return-color;
  // border: 1px solid red;
}
.right-box:hover{
  background-color: #A4A6AD;
}
.right-box span{
float: left;
color: $white;
font-size: $font-size-medium;
 line-height: 40px;
  //  border: 1px solid red;

}
.right-box img{
  width:30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box{
width: 98%;
height: 800px;
margin: 0 auto;
border-radius: 8px;
background-color: $white;
border: 1px solid $bordercolor;
}
.table-box{
  width: 50%;
  // height: 243px;
  margin: 0 auto;
  margin-top: 200px;
  border-top: 1px solid $bordercolor;
    border-left: 1px solid $bordercolor;
      border-right: 1px solid $bordercolor;
}
.item-box{
  width:100%;
  // height: 60px;
  display: flex;
  border-bottom: 1px solid $bordercolor;
}
.number-box{
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid  $bordercolor;
}
.number1-box{
  flex: 1;
  line-height: 60px;
    margin-left: 10%;
}
.el-switch{
  margin-top: 20px;
  margin-left: 10%;
}
.number2-box{
  width: 20%;
  height: 120px;
  line-height: 120px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid  $bordercolor;
}
.number3-box{
  flex: 1;
  line-height: 80px;
    margin-left: 10%;
}
.number1-box input{
  width: 90%;
  height: 58px;
  border: none;
  outline: none;
  font-size: 14px;
  color: #515151;
  margin-left: 10%;
  // text-align: center;
}
.block{
  // text-align: center;
  margin-top: 10px;
  margin-left: 10%;
}
.btn-box{
  width: 20%;
  height: 60px;
  margin: 0 auto;
  padding-left: 100px;
  margin-top: 100px;
  // border: 1px solid red;
}
</style>
